﻿using System.ComponentModel;
using System.Drawing.Design;

namespace AjaxTools
{
    public class ExtSimpleColumn : InfoOwnerCollectionItem
    {
        string _columnName = "";
        string _headerText = "";
        string _dataField = "";
        string _fieldType = "string";
        string _textAlign = "left";
        string _fomatter = "";
        int _width = 75;
        bool _allowSort = false;
        bool _resizable = true;
        bool _isKeyField = false;

        [Category("Infolight")]
        [DefaultValue("")]
        [NotifyParentProperty(true)]
        public string ColumnName
        {
            get { return _columnName; }
            set { _columnName = value; }
        }

        [Category("Infolight")]
        [DefaultValue("")]
        [NotifyParentProperty(true)]
        public string HeaderText
        {
            get { return _headerText; }
            set { _headerText = value; }
        }

        [Category("Infolight")]
        [DefaultValue("")]
        [NotifyParentProperty(true)]
        [Editor(typeof(ExtStaticStringEditor), typeof(UITypeEditor))]
        public string DataField
        {
            get { return _dataField; }
            set { _dataField = value; }
        }

        [Category("Infolight")]
        [DefaultValue("string")]
        [NotifyParentProperty(true)]
        [Editor(typeof(ExtStaticStringEditor), typeof(UITypeEditor))]
        public string FieldType
        {
            get { return _fieldType; }
            set { _fieldType = value; }
        }

        [Category("Infolight")]
        [DefaultValue("left")]
        [NotifyParentProperty(true)]
        [Editor(typeof(ExtStaticStringEditor), typeof(UITypeEditor))]
        public string TextAlign
        {
            get { return _textAlign; }
            set { _textAlign = value; }
        }

        [Category("Infolight")]
        [DefaultValue("")]
        [Description("define a javascript function which returns a formatted display value./n/rthe function is something like:function converter(value,column,record,rowIndex,columnIndex,store){return 'display';}")]
        [NotifyParentProperty(true)]
        public string Formatter
        {
            get { return _fomatter; }
            set { _fomatter = value; }
        }

        [Category("Infolight")]
        [DefaultValue(75)]
        [NotifyParentProperty(true)]
        public int Width
        {
            get { return _width; }
            set { _width = value; }
        }

        [Category("Infolight")]
        [DefaultValue(false)]
        [NotifyParentProperty(true)]
        public bool AllowSort
        {
            get { return _allowSort; }
            set { _allowSort = value; }
        }

        [Category("Infolight")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        public bool Resizable
        {
            get { return _resizable; }
            set { _resizable = value; }
        }

        [Category("Infolight")]
        [DefaultValue(false)]
        [NotifyParentProperty(true)]
        public bool IsKeyField
        {
            get { return _isKeyField; }
            set { _isKeyField = value; }
        }

        [NotifyParentProperty(true)]
        public override string Name
        {
            get { return _columnName; }
            set { _columnName = value; }
        }

        public override string ToString()
        {
            return _columnName;
        }
    }

    public class ExtGridColumn : ExtSimpleColumn
    {
        public ExtGridColumn()
        {
        }

        string _editControlId = "";
        string _defaultValue = "";
        ValidateType _validType = ValidateType.None;
        ExtGridEditor _editor = ExtGridEditor.TextBox;
        bool _allowNull = true;
        bool _visible = true;
        bool _isExpandColumn = true;
        bool _newLine = true;

        [Category("Infolight")]
        [DefaultValue("")]
        [NotifyParentProperty(true)]
        [Editor(typeof(ExtStaticStringEditor), typeof(UITypeEditor))]
        public string EditControlId
        {
            get { return _editControlId; }
            set { _editControlId = value; }
        }

        [Category("Infolight")]
        [DefaultValue("")]
        [NotifyParentProperty(true)]
        public string DefaultValue
        {
            get { return _defaultValue; }
            set { _defaultValue = value; }
        }

        [Category("Infolight")]
        [DefaultValue(typeof(ValidateType), "None")]
        [NotifyParentProperty(true)]
        public ValidateType ValidType
        {
            get { return _validType; }
            set { _validType = value; }
        }

        [Category("Infolight")]
        [DefaultValue(typeof(ExtGridEditor), "TextBox")]
        [NotifyParentProperty(true)]
        public ExtGridEditor Editor
        {
            get 
            {
                return _editor;
            }
            set 
            {
                _editor = value;
                //if (_editor == ExtGridEditor.DateTimePicker)
                //{
                //    PropertyDescriptor propEditId = TypeDescriptor.GetProperties(this)["EditControlId"];
                //}
            }
        }

        [Category("Infolight")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        public bool AllowNull
        {
            get { return _allowNull; }
            set { _allowNull = value; }
        }

        [Category("Infolight")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        public bool Visible
        {
            get { return _visible; }
            set { _visible = value; }
        }

        [Category("Infolight")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        public bool ExpandColumn
        {
            get { return _isExpandColumn; }
            set { _isExpandColumn = value; }
        }

        [Category("Infolight")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        public bool NewLine
        {
            get { return _newLine; }
            set { _newLine = value; }
        }
    }
}
